<template lang="">
    <div>
        <el-form :inline="true" :model="formInline" class="demo-form-inline" style="text-align: left">
            <el-form-item label="厂牌型号：">
                <el-input v-model="formInline.brandModel"></el-input>
            </el-form-item>
            <el-form-item label="车牌号：">
                <el-input v-model="formInline.carNum"></el-input>
            </el-form-item>
            <el-form-item label="司机姓名：">
                <el-input v-model="formInline.driverName"></el-input>
            </el-form-item>
            <el-form-item label="所属公司：">
                <el-input v-model="formInline.company"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="getCar">查询</el-button>
                <el-button @click="resetForm">重置</el-button>
                <!-- <el-button type="primary">新增</el-button> -->
            <el-button type="primary" @click="deleteallcar">批量删除</el-button>
            </el-form-item>
        </el-form>
        <br>
        <el-dialog title="具体情况" :visible.sync="dialogVisible" width="1200px" >
          <el-table border :data="postData">
                <el-table-column property="brandModel" label="厂牌型号" align="center"></el-table-column>
                <el-table-column property="carNum" label="车牌号" align="center"></el-table-column>
                <el-table-column property="driverName" label="司机姓名" align="center"></el-table-column>
                <el-table-column property="company" label="所属公司" align="center"></el-table-column>
                <el-table-column property="vehicleType" label="车型" align="center"></el-table-column>
                <el-table-column property="carColor" label="车辆颜色" align="center"></el-table-column>
                <el-table-column property="payDate" label="购置日期" align="center"></el-table-column>
                <el-table-column property="operationNum" label="营运证号" align="center"></el-table-column>
                <el-table-column property="insuranceExpireTime" label="保险到期时间" align="center"></el-table-column>
                <el-table-column property="checkDueTime" label="年检到期时间" align="center"></el-table-column>
                <el-table-column property="maintenanceNum" label="保养公里设置" align="center"></el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="dialogVisible = false">关闭</el-button>
            </span>
        </el-dialog>

        <el-table border :cell-style="rowStyle" ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
            @selection-change="handleSelectionChange">
            <el-table-column fixed type="selection" width="55" align="center">
            </el-table-column>
            <el-table-column fixed prop="brandModel" label="厂牌型号" align="center">
            </el-table-column>
            <el-table-column fixed prop="carNum" label="车牌号" align="center">
            </el-table-column>
            <el-table-column fixed prop="driverName" label="司机姓名" align="center">
            </el-table-column>
            <el-table-column prop="company" label="所属公司" align="center">
            </el-table-column>
            <el-table-column prop="vehicleType" label="车型（长*宽*高）" align="center" >
            </el-table-column>
            <el-table-column prop="carColor" label="车辆颜色" align="center">
            </el-table-column>
            <el-table-column prop="payDate" label="购置日期" align="center">
            </el-table-column>
            <el-table-column prop="operationNum" label="营运证号" align="center">
            </el-table-column>
            <el-table-column prop="insuranceExpireTime" label="保险到期时间" align="center">
            </el-table-column>
            <el-table-column prop="checkDueTime" label="年检到期时间" align="center">
            </el-table-column>
            <el-table-column prop="maintenanceNum" label="保养公里设置" align="center">
            </el-table-column>
            <el-table-column fixed="right" label="操作" align="center">
                <template slot-scope="scope">
                    <!-- <el-button type="text" >编辑</el-button> -->
                    <el-link type="primary" @click="showcar(scope.row)">查看</el-link>
                    <el-link type="danger" @click="deletecar(scope.row)">删除</el-link>
                </template>
            </el-table-column>
        </el-table>
        <br>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="formInline.pageIndex" :page-sizes="[10, 20, 30, 40]" :page-size="formInline.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="count">
        </el-pagination>
    </div>
</template>
<script>
import {
  getcarapi,
  addcarapi,
  updatcarapi,
  deletecarapi,
  deleteallcarapi,
} from "@/api/area/Car";
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        pageIndex: 1,
        pageSize: 10,
        brandModel: "",
        carNum: "",
        driverName: "",
        company: "",
      },
      count: 0,
      dialogVisible: false,
      formData: {},
      postData: []
    };
  },
  methods: {
    rowStyle() {
      return "text-align:center";
    },
    getCar() {
      getcarapi(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pageSize = val;
      this.getCar();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pageIndex = val;
      this.getCar();
    },
    resetForm() {
      (this.formInline.brandModel = ""),
        (this.formInline.carNum = ""),
        (this.formInline.driverName = ""),
        (this.formInline.company = "");
    },
    deletecar(row) {
      if (confirm("确定要删除吗？")) {
        deletecarapi(row).then((res) => {
          if (res.data.message == "操作成功") {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.getCar();
          } else {
            this.$message({
              message: "删除失败",
              type: "error",
            });
          }
        });
      }
    },
    deleteallcar() {
      var stucheck = this.$refs["multipleTable"].selection;
      if (stucheck.length == 0) {
        this.$message.warning("至少选择一项数据");
      } else {
        var checkall = [];
        stucheck.forEach((element) => {
          checkall.push(element);
        });
        if (confirm("确定要删除吗？")) {
          deleteallcarapi(checkall).then((res) => {
            if (res.data.message == "操作成功") {
              this.$message({
                message: "删除成功",
                type: "success",
              });
              this.getCar();
            } else {
              this.$message({
                message: "删除失败",
                type: "error",
              });
            }
          });
        }
      }
    },
    showcar(row) {
      this.dialogVisible = true;
      this.formData = row;
      this.postData.push(row)
    },
  },
  created() {
    this.getCar();
  },
};
</script>
<style lang="">
</style>